import Utils from './mod.utils';

export default {
  create: function (context, params) {
    var type = params.type ? params.type : 'standalone';
    var photos = params.photos ? params.photos : [];
    var theme = params.theme ? params.theme : 'dark';
    var navbar = params.navbar ? params.navbar : true;
    var toolbar = (params.toolbar != undefined && params.toolbar != null && typeof params.toolbar == "boolean") ? params.toolbar : true;
    var backLinkText = params.backLinkText ? params.backLinkText : '关闭';
    var navbarOfText = params.navbarOfText ? params.navbarOfText : '/';
    var swiper = params.swiper ? params.swiper : null;
    var opened = params.opened ? params.opened : null;
    var closed = params.closed ? params.closed : null;
    var change = params.change ? params.change : null;
    var tap = params.tap ? params.tap : null;
    var click = params.click ? params.click : null;
    var doubleTap = params.doubleTap ? params.doubleTap : null;
    var photoBrowser = context.$f7.photoBrowser.create({
      type: type,
      photos: photos,
      theme: theme,
      navbar: navbar,
      toolbar: toolbar,
      backLinkText: backLinkText,
      navbarOfText: navbarOfText,
      swiper: swiper,
      on: {
        opened: function () {
          if (opened != null) {
            opened();
          }
        },
        closed: function () {
          Utils.fireEvent(context, Utils.kEvents.updatePreClose, null);
          if (closed != null) {
            closed();
          }
        },
        slideChange: function () {
          const _this = this;
          if (change != null) {
            change(_this.activeIndex);
          }
        },
        doubleTap: function () {
          const _this = this;
          if (doubleTap != null) {
            doubleTap();
          }
        },
        tap: function () {
          const _this = this;
          if (tap != null) {
            tap();
          }
        },
        click: function () {
          const _this = this;
          if (click != null) {
            click();
          }
        }
      },
    });
    return photoBrowser;
  },
}